package com.corpgovernment.organization.convert;

import com.corpgovernment.api.basic.dto.OrgDTO;
import com.corpgovernment.api.basic.vo.MbUserRegisterIdentityVO;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author jhxue
 * @create 2022-02-18-16:36
 */
@Component
public class LoginConvert {

	/**
	 * 数据转换
	 *
	 * @param orgList
	 * @param state
	 * @return
	 */
	public List<MbUserRegisterIdentityVO> convert(List<OrgDTO> orgList, String state) {
		if (CollectionUtils.isEmpty(orgList)) {
			return new ArrayList<>();
		}
		return orgList.stream().filter(Objects::nonNull).map(e -> {
			MbUserRegisterIdentityVO target = new MbUserRegisterIdentityVO();
			target.setDeptId(e.getDeptId());
			target.setDeptName(e.getDeptName());
			target.setCorpId(e.getCorpId());
			target.setCorpName(e.getCorpName());
			target.setState(e.getApprovalStatus() == 1 ? "审核通过" : state);
			target.setStatus(e.getApprovalStatus());
			return target;
		}).collect(Collectors.toList());
	}
}
